<template>
  <view class="waybill">
    <scroll-view class="sl-sv" scroll-y="true" @scrolltolower="scrolower">
      <view class="box" v-if="orderList.length">
        <view class="item" v-for="(item, index) in orderList" :key="index">
          <view class="title">{{ item.track }}</view>
          <view class="pack">仓库：{{ item.warehouse }}</view>
          <view class="time">预报：{{item.add_time}}</view>
          <view class="article">物品：		  
			  <text v-for="it in item.info" :key="it.id">
				  {{item.type_name}}/{{it.name}}{{it.brand?'/'+it.brand:''}}{{it.spe?'/'+it.spe:''}}{{it.num?'/'+it.num:''}}{{it.price?'/'+it.price:''}}；;
			  </text>
		  </view>
          <view class="btnbox">
			<view class="btn" @click="connection(item)">联系客服</view>
            <view class="btn" @click="onCancel(item)">提交发货</view>
            <view class="btn cancel" @click="detail(item, 'no')">详情</view>
          </view>
        </view>
      </view>
	  <view v-else class="empty" >
	  	暂无数据...
	  </view>
    </scroll-view>
    <view class="search" @click="open">
      <u-icon name="search" color="#2354E3" size="40"></u-icon>
    </view>
    <!-- 搜索 -->
    <u-popup
      :show="popupShow"
      :round="10"
      mode="bottom"
      :closeable="true"
      @close="close"
    >
      <view class="content">
        <view class="ptitle">包裹查找</view>
        <view class="pcontet">
          <u-input
            placeholder="输入包裹追踪号"
            border="none"
            v-model="searchValue"
            :customStyle="inputStyle"
          ></u-input>
          <!-- placeholderStyle="{'font-size': '28rpx';
        'color':' #999999'}" -->
        </view>
        <view class="pbtn space-between">
          <view class="btn btn1" @click="searchValue = ''">重置</view>
          <view class="btn btn2" @click="onSearch">查询</view>
        </view>
      </view>
    </u-popup>
  </view>
</template>

<script>
export default {
  data() {
    return {
      // 订单列表
      orderList: [],
      // 输入框样式
      inputStyle: {
        "background-color": "#F5F5F5",
        "border-radius": "5rpx",
        "padding-left": "43rpx",
        padding: "30rpx",
      },
      // 搜索值
      searchValue: "",
      // 搜索框
      popupShow: false
    };
  },
  onLoad(options) {
	  this.getDataList();
  },
  methods: {
	getDataList(){
	  this.$api.post({
		  url: "/ebapi/public_api/reservation_order_after",
		  success: (res) => {
			  this.orderList = res.map(item=>{
				  item.info = JSON.parse(item.info);	
				  return item;
			  })
			  console.log(this.orderList,"this.orderList")
		},
	   })
	},
    // 触底事件
    scrolower() {},
	// 联系我们
	connection(){
		uni.navigateTo({
			url:"/pages/my/about"
		})
	},
    //
    onCancel(it) {
      uni.showModal({
        title: "提示",
        content: "是否确认提交发货？",
        success: (res) => {
          if (res.confirm) {
            // 确定
			let checkArrData = [it];
			this.$uniApi.to(`/pages/home/placeOrder?checkArrData=${JSON.stringify(checkArrData)}`);
          } else if (res.cancel) {
            // 取消
            console.log("用户点击了取消");
          }
        },
      });
    },
    // 删除订单
    del(item) {
      uni.showModal({
        title: "提示",
        content: "是否确认删除该订单？",
        success: (res) => {
          if (res.confirm) {
            // 确定
            this.orderList.forEach((goods, index) => {
              if (goods.id == item.id) {
                this.orderList.splice(index, 1);
              }
            });
          } else if (res.cancel) {
            // 取消
            console.log("用户点击了取消");
          }
        },
      });
    },
    // 编辑订单
    edit(eitem) {
      let info = JSON.stringify(eitem);
      this.$uniApi.to("/pages/my/waybillEdit?info=" + info);
    },
    // 订单详情
    detail(ditem, type) {
		this.$uniApi.to(`/pages/home/packageDetail?id=${ditem.id}`);
      // this.$uniApi.to("/pages/home/packageDetail");
    },
    // 搜索显示
    open() {
      this.popupShow = true;
    },
    // 搜索隐藏
    close() {
      this.popupShow = false;
    },
    // 查询
    onSearch() {
	  if (this.searchValue) {
		this.popupShow = false;
	    this.$uniApi.to(`/pages/search/searchDetail?title=${this.searchValue}`);
	  } else {
	    this.$u.toast("请输入要查询的追踪号");
	  }
    },
  },
};
</script>

<style lang="scss">
page {
  padding: 0;
}

.waybill {
  padding: 24rpx;

  .sl-sv {
    height: 90vh;
  }

  .box {
    height: 100%;

    .item {
      // height: 433rpx;
      background: #ffffff;
      box-shadow: 0rpx 2rpx 10rpx 1rpx rgba(0, 0, 0, 0.08);
      border-radius: 16rpx 16rpx 16rpx 16rpx;
      opacity: 1;
      padding: 36rpx 36rpx 47rpx;
      margin-bottom: 24rpx;

      .title {
        font-size: $uni-text-size-title;
        color: $uni-color-main;
        font-weight: bold;
      }

      .pack {
        margin: 35rpx 0;
      }

      .time {
        margin-bottom: 35rpx;
      }

      .article {
        margin-bottom: 48rpx;
      }

      .btnbox {
        color: $uni-text-color-grey;
        display: flex;
        justify-content: flex-end;

        .btn {
          border: 1px solid $uni-text-color-grey;
          padding: 15rpx 40rpx;
          border-radius: 5rpx;
          margin-left: 24rpx;
        }

        .cancel {
          color: #2354e3;
          border: 1px solid #2354e3;
        }
      }
    }
  }

  .search {
    position: absolute;
    right: 24rpx;
    bottom: 2vh;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 96rpx;
    height: 96rpx;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0rpx 3rpx 6rpx 1rpx rgba(0, 0, 0, 0.16);
    opacity: 1;
  }

  .content {
    padding: 35rpx 62rpx 50rpx;

    .ptitle {
      font-size: 36rpx;
      font-weight: bold;
      text-align: center;
      margin-top: 30rpx;
    }

    .pcontet {
      color: #999999;
      font-size: $uni-text-size-title;
      margin: 40rpx 0;
    }

    .pbtn {
      text-align: center;
      font-size: $uni-text-size-title;
      padding: 0 85rpx;

      .btn {
        padding: 18rpx 68rpx;
        border-radius: 6rpx;
      }

      .btn1 {
        border: 1px solid #999999;
      }

      .btn2 {
        background-color: $uni-color-main;
        color: #ffffff;
      }
    }
  }
}
</style>
